import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.wp.usermodel.HeaderFooterType;
import org.apache.poi.xwpf.usermodel.*;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigInteger;

/**
 * 使用POI来操作word
 */
public class POIWordDemo {
    static final String docPat="/Users/wuxinbo/poiDemo/test.docx";
    static final String IMG_PATH="/Users/wuxinbo/poiDemo/21.jpg";
    /**
     * 入口测试
     * @param args
     */
    public static void main(String args []) throws IOException, InvalidFormatException {
        XWPFDocument document =new XWPFDocument();
        XWPFTable table = document.createTable(3, 2);
        table.getRow(1).getCell(1).setText("hello");
        table.getRow(0).getCell(0).setText("byebye");
//        XwPF
        XWPFParagraph content = document.createParagraph();
        XWPFRun contentRun = content.createRun();
        contentRun.setText("为本文档主要目的是明确三峡数字博物馆建设工程信息系统”中的子系统“风险管控指挥系统”用户需要的实际功能，同时为软件开发者提供开发、测试依据。");
        contentRun.setFontFamily("宋体");
        contentRun.setFontSize(10);
        contentRun.addBreak();
        XWPFRun contentRun1 = content.createRun();
        contentRun1.setText("这是第二段");
        contentRun.addBreak();
//        content.getBody().getPart().
        XWPFPicture xwpfPicture = contentRun.addPicture(new FileInputStream(IMG_PATH), XWPFDocument.PICTURE_TYPE_JPEG, "21.jpg", 200, 600);
        content.setIndentationFirstLine(2);

        content.setNumID(BigInteger.valueOf(10));
        content.setAlignment(ParagraphAlignment.LEFT);
        XWPFHeader header = document.createHeader(HeaderFooterType.DEFAULT);
        XWPFParagraph paragraph = header.createParagraph();
        XWPFRun run = paragraph.createRun();
        run.addTab();
        run.setText("123");
        paragraph.setNumID(BigInteger.valueOf(2));
        document.write(new FileOutputStream(docPat));
//        XWPFHeader header =new XWPFHeader();
//        header.createParagraph().set
    }
}
